Skip to content

chore(rivetkit): add child spans for logging#4734

Closed
NathanFlurry wants to merge 1 commit into04-23-fix_rivetkit-core_orphan_engine_process_and_detect_crashesfrom
04-23-chore_rivetkit_add_child_spans_for_logging
Closed

chore(rivetkit): add child spans for logging#4734
NathanFlurry wants to merge 1 commit into04-23-fix_rivetkit-core_orphan_engine_process_and_detect_crashesfrom
04-23-chore_rivetkit_add_child_spans_for_logging

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 24, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_orphan_engine_process_and_detect_crashes branch from fbf0f28 to b73cea0 Compare April 24, 2026 09:52
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from fbc8b08 to 475a302 Compare April 24, 2026 09:52
@NathanFlurry NathanFlurry mentioned this pull request Apr 24, 2026
11 tasks
@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

PR Review: chore(rivetkit): add child spans for logging

This PR bundles three concerns: tracing/span propagation, a new graceful shutdown system, and a switch to JSON log format. The core architecture is solid. The RegistryState machine and the watch-based stop latch are well-designed. A few issues worth addressing before merging.

Log Level Density

dispatch_action_through_task emits 5 info!-level lines per action call: three in registry/dispatch.rs (before send, after queue, after reply) plus two more in ActorTask::run action match arm. Under load these will dominate log volume. Downgrade to debug! or trace!. Same for inspector_ws.rs where each websocket message exchange emits several info! lines.

Duplicate Constant

SHUTDOWN_DRAIN_TIMEOUT: Duration = Duration::from_secs(20) is defined independently in both rivetkit-core/src/registry/mod.rs and rivetkit-core/src/serverless.rs. Extract to a shared location to prevent drift.

Redundant Structured Fields

dispatch_event is instrumented with actor_id = %ctx.inner().actor_id() via #[tracing::instrument], but inner tracing::info! / tracing::warn! calls in the ActorEvent::Action branch also log actor_id manually. The span already carries the field — the inline copies are redundant.

format_actor_key Re-export

format_actor_key is re-exported from the rivetkit_core crate root in lib.rs. This helper exists purely for formatting log fields and does not belong on the public crate surface. Keep it pub(crate) or mark it #[doc(hidden)].

Comment Style Violations

A few new comments use the dash/colon pattern CLAUDE.md discourages (e.g. // not_global: true to avoid caching...). Per CLAUDE.md: write complete sentences, avoid dash-separated clauses.

Missing Trailing Newline

rivetkit-rust/engine/artifacts/errors/registry.shut_down.json is missing a trailing newline. All other error artifacts in that directory have one.

spawn_task Allocates actor_id: String Unconditionally

The spawn_task helper in napi_actor_events.rs takes actor_id: String but only uses it in a single error log path. This allocates per call even on the happy path. Consider &str / Cow<str> or inlining the field at the call site.

Shutdown During Build Race

In registry.rs (NAPI), when shutdown() fires while state is BuildingServerless, the transition to ShutDown relies on the builder task completing normally. If the builder is cancelled mid-await the state could be stuck in ShuttingDown. A timeout guard or an explicit drop-to-ShutDown in the builder error path would make this more robust.

Test Coverage Gaps

The new RegistryState machine and shutdown_and_wait path have no unit tests. Tests covering concurrent ensure_serverless_runtime calls, shutdown() racing with an in-progress build, and wait_stopped under the drain timeout would significantly increase confidence. The TypeScript #runShutdown timeout path also has no coverage.

Minor: stopped_tx in Test Helpers

stopped_tx in test helpers is initialized with watch::channel(true).0 (pre-latch = already stopped). Fine for tests that do not call wait_stopped(), but could silently mask bugs in tests that use wait_stopped to verify an actual shutdown sequence.

@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_orphan_engine_process_and_detect_crashes branch from b73cea0 to c59f860 Compare April 24, 2026 10:19
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from 475a302 to 36cef20 Compare April 24, 2026 10:19
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from 36cef20 to a70e758 Compare April 24, 2026 10:32
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from a70e758 to e676e10 Compare April 24, 2026 11:48
@NathanFlurry NathanFlurry force-pushed the 04-23-fix_rivetkit-core_orphan_engine_process_and_detect_crashes branch from 5ba2e02 to ae1b9e4 Compare April 24, 2026 12:14
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from e676e10 to 98121fe Compare April 24, 2026 12:14
@NathanFlurry NathanFlurry force-pushed the 04-23-chore_rivetkit_add_child_spans_for_logging branch from 98121fe to ee43585 Compare April 24, 2026 12:32
@NathanFlurry
Copy link
Copy Markdown
Member Author

Landed in main via stack-merge fast-forward push. Commits are in main; closing to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant